package com.ruoyi.web.controller.dispatch;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DispatchEnergyConsumption;
import com.ruoyi.system.service.IDispatchEnergyConsumptionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 能耗分析Controller
 * 
 * @author ruoyi
 * @date 2025-03-02
 */
@RestController
@RequestMapping("/system/dispatchEnergyConsumption")
public class DispatchEnergyConsumptionController extends BaseController
{
    @Autowired
    private IDispatchEnergyConsumptionService dispatchEnergyConsumptionService;

    /**
     * 查询能耗分析列表
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchEnergyConsumption:list')")
    @GetMapping("/list")
    public TableDataInfo list(DispatchEnergyConsumption dispatchEnergyConsumption)
    {
        startPage();
        List<DispatchEnergyConsumption> list = dispatchEnergyConsumptionService.selectDispatchEnergyConsumptionList(dispatchEnergyConsumption);
        return getDataTable(list);
    }

    /**
     * 导出能耗分析列表
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchEnergyConsumption:export')")
    @Log(title = "能耗分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DispatchEnergyConsumption dispatchEnergyConsumption)
    {
        List<DispatchEnergyConsumption> list = dispatchEnergyConsumptionService.selectDispatchEnergyConsumptionList(dispatchEnergyConsumption);
        ExcelUtil<DispatchEnergyConsumption> util = new ExcelUtil<DispatchEnergyConsumption>(DispatchEnergyConsumption.class);
        util.exportExcel(response, list, "能耗分析数据");
    }

    /**
     * 获取能耗分析详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchEnergyConsumption:query')")
    @GetMapping(value = "/{energyConsumptionId}")
    public AjaxResult getInfo(@PathVariable("energyConsumptionId") Long energyConsumptionId)
    {
        return success(dispatchEnergyConsumptionService.selectDispatchEnergyConsumptionByEnergyConsumptionId(energyConsumptionId));
    }

    /**
     * 新增能耗分析
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchEnergyConsumption:add')")
    @Log(title = "能耗分析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DispatchEnergyConsumption dispatchEnergyConsumption)
    {
        return toAjax(dispatchEnergyConsumptionService.insertDispatchEnergyConsumption(dispatchEnergyConsumption));
    }

    /**
     * 修改能耗分析
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchEnergyConsumption:edit')")
    @Log(title = "能耗分析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DispatchEnergyConsumption dispatchEnergyConsumption)
    {
        return toAjax(dispatchEnergyConsumptionService.updateDispatchEnergyConsumption(dispatchEnergyConsumption));
    }

    /**
     * 删除能耗分析
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchEnergyConsumption:remove')")
    @Log(title = "能耗分析", businessType = BusinessType.DELETE)
	@DeleteMapping("/{energyConsumptionIds}")
    public AjaxResult remove(@PathVariable Long[] energyConsumptionIds)
    {
        return toAjax(dispatchEnergyConsumptionService.deleteDispatchEnergyConsumptionByEnergyConsumptionIds(energyConsumptionIds));
    }
}
